/**
 * Author: Dmitry Ustimov
 * Date: 5/31/13
 * Time: 8:13 PM
 */

package com.gmail.dmitryustimov.ms.java7.mediator.mod.work.demo.col10event1;

import com.gmail.dmitryustimov.ms.java7.patternslib.mediator.Colleague;
import com.gmail.dmitryustimov.ms.java7.patternslib.mediator.SubscriberAction;

import java.math.BigDecimal;

public class ConcreteColleague9 extends AbstractColleague {

    private Mediator mediator;
    private BigDecimal sum = BigDecimal.valueOf(0);

    public ConcreteColleague9(String name, Mediator mediator) {
        this.name = name;
        this.mediator = mediator;
        this.mediator.getEvent1Publisher().subscribe(this.new Event1Action());
    }

    public void makeEvent() {
        event1Publisher.publish(new Event1("C9E1"), this);
    }

    private class Event1Action extends SubscriberAction<Event1> {
        public Event1Action() {
            super(ConcreteColleague9.this);
        }

        @Override
        public void process(Event1 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
        }
    }
}
